package info.brenstar.boxedin.rooms;

import org.newdawn.slick.*;

import info.brenstar.boxedin.core.Room;
import info.brenstar.boxedin.core.SpriteGroup;
import info.brenstar.boxedin.collisions.*;
import info.brenstar.boxedin.sprites.*;

public class TestRoom extends Room {
	
	private Player player;
	private CollisionMap map;
	
	public TestRoom() {
		super();
	}
	
	@Override
	public void init() {
		map = new CollisionMap(200,160);
		CollisionChecker.Map = map;
		player = new Player(320, 320);
		player.init();
		entities.add(player);
		map.add(player);
		
		Box box = new Box(64f, 128f);
		entities.add(box);
		
		Sector[] neighbors = map.getNeighbors(player);
		for (Sector sect : neighbors) {
			System.out.println(sect);
		}
		
		for (int i = 0; i != 25; i++) {
			Platform p = new Platform(i*32f, 608f, i*10);
			p.init();
			if (i == 0) { p.setTile(1,7); }
			else if (i == 24) { p.setTile(1,8); }
			else { p.setTile(0, 1); }
			entities.add(p);
			p = new Platform(i*32f, 0f, 250 - i*10);
			p.init();
			if (i == 0) { p.setTile(0,7); }
			else if (i == 24) { p.setTile(0,8); }
			else { p.setTile(2, 1); }
			entities.add(p);
		}
		for (int i = 1; i != 19; i++ ) {
			Platform p = new Platform(0f, i*32f, 250 - i*12);
			p.init();
			p.setTile(1, 2);
			entities.add(p);
			p = new Platform(768f, i*32f, i*12);
			p.init();
			p.setTile(1, 0);
			entities.add(p);
		}
		
	}

	@Override
	public void update(GameContainer container, int delta) {
		entities.updateAll();
		entities.pollInput(container.getInput());
	}

	@Override
	public void render(GameContainer container, Graphics g) {
		g.setColor(new Color(128,128,128,24));
		
		for (int i = 0; i != 25; i++) {
			g.drawLine(i*32, 0, i*32, 640);
		}
		
		for (int i = 0; i != 20; i++) {
			g.drawLine(0, i*32, 800, i*32);
		}
		
		g.setColor(Color.white);
		entities.renderAll(g);
		map.debug(g);
	}
	
	public CollisionMap getMap() {
		return this.map;
	}
	
}
